package com.server.transaction.factory;

import com.server.transaction.handler.GlobalUncaughtExceptionHandler;
import lombok.AllArgsConstructor;

import java.util.concurrent.ThreadFactory;

/**
 * @author gyuan
 * @date 2023/9/19 9:32
 * @description
 */
@AllArgsConstructor
public class GlobalThreadFactory implements ThreadFactory {

    private ThreadFactory threadFactory;

    @Override
    public Thread newThread(Runnable r) {
        // 使用spring的线程工厂创建线程
        Thread thread = threadFactory.newThread(r);
        // 设置线程的异常处理器
        thread.setUncaughtExceptionHandler(GlobalUncaughtExceptionHandler.getInstance());
        return thread;
    }
}
